package com.cgc.venus.server.core.k8s.inter;

import com.cgc.venus.server.core.exception.VenusException;
import io.fabric8.kubernetes.api.model.*;
import io.fabric8.kubernetes.api.model.apps.*;
import io.fabric8.kubernetes.api.model.autoscaling.v1.HorizontalPodAutoscaler;
import io.fabric8.kubernetes.api.model.batch.Job;
import io.fabric8.kubernetes.api.model.extensions.Ingress;
import io.fabric8.kubernetes.api.model.extensions.IngressList;
import io.fabric8.kubernetes.api.model.networking.NetworkPolicy;
import io.fabric8.kubernetes.client.KubernetesClient;


import java.util.List;
import java.util.Map;

/**
 * Created by 业哥 on 2017/11/16.
 * kubernetes 应用管理接口
 */
public interface K8sManageService {

    public KubernetesClient getK8sClient();

    /*
    * 1: 根据上传的yaml文件,创建命名空间
    * 在一个Kubernetes集群中可以使用namespace创建多个“虚拟集群”，这些namespace之间可以完全隔离，也可以通过某种方式，让一个namespace中的service可以访问到其他的namespace中的服务，
    * */
    public Namespace createNamespaceByYaml(String yamlContent) throws VenusException;

    /*
    * 2: 根据上传的yaml文件,创建node信息
    * */
    public Node createNodeByYaml(String yamlContent) throws VenusException;

    /*
    * 3: 根据上传的yaml文件,创建pod
    * */
    public Pod createPodByYaml(String yamlContent) throws VenusException;

    /*
    * 4: 根据上传的yaml文件,创建service
    * */
    public Service createServiceByYaml(String yamlContent) throws VenusException;

    /*
    * 5: 根据上传的yaml文件,创建PersistentVolume
    * */
    public PersistentVolume createPersistentVolumeByYaml(String yamlContent) throws VenusException;

    /*
    * 6: 根据上传的yaml文件,创建 PersistentVolumeClaim
    * */
    public PersistentVolumeClaim createPersistentVolumeClaimByYaml(String yamlContent) throws VenusException;

    /*
    * 7: 根据上传的yaml文件,创建Deployment
    * */
    public Deployment createDeploymentByYaml(String yamlContent) throws VenusException;

    /*
    * 8: 根据上传的yaml文件,创建 Secret
    * */
    public Secret createSecretByYaml(String yamlContent) throws VenusException;

    /*
    * 9: 根据上传的yaml文件,创建 StatefulSet
    * */
    public StatefulSet createStatefulSetByYaml(String yamlContent) throws VenusException;

    /*
    * 10: 根据上传的yaml文件,创建 ServiceAccount
    * */
    public ServiceAccount createServiceAccountByYaml(String yamlContent) throws VenusException;

    /*
    * 11: 根据上传的yaml文件,创建 ReplicaSet
    * */
    public ReplicaSet createReplicaSetByYaml(String yamlContent) throws VenusException;

    /*
    * 12: 根据上传的yaml文件,创建 ReplicationCtronller
    * */
    public ReplicationController createReplicationControllerByYaml(String yamlContent) throws VenusException;

    /*
    * 13: 根据上传的yaml文件,创建 Job
    * */
    public Job createJobByYaml(String yamlContent) throws VenusException;

    /*
    * 14: 根据上传的yaml文件,创建Ingress
    * */
    public Ingress createIngressByYaml(String yamlContent) throws VenusException;

    /*
    * 15: 根据上传的yaml文件,创建 ConfigMap
    * */
    public ConfigMap createConfigMapByYaml(String yamlContent) throws VenusException;


    /*
    * 16: 根据上传的yaml文件,创建HorizontalPodAutoscaler
    * */
    public HorizontalPodAutoscaler createHorizontalPodAutoscalerByYaml(String yamlContent) throws VenusException;

    /*
    * 17: 根据上传的yaml文件,创建 NetworkPolicy
    * */
    public NetworkPolicy createNetworkPolicyByYaml(String yamlContent) throws VenusException;

    /*
    * 18: 根据上传的yaml文件,创建 daemonset
    * */
    public DaemonSet createDaemonSetByYaml(String yamlContent) throws VenusException;


    /*
    * 19: 根据空间名,应用名称,获得deployment资源信息
    * @param namespace 应用空间
    * @param appNameKube 应用名称
    * */
    public Deployment getDeployment(String namespace, String appNameKube) throws VenusException;


    /*
    * 20: 根据空间名称获得,statefulset 资源信息
    * @param namespace 应用空间
    * @param appNameKube 应用名称
    * */
    public StatefulSet getStatefulSet(String namespace,String appNameKube) throws VenusException;


    /*
    * 21: 根据空间名称得到所有pod信息
    * @param namespace
    * */
    public PodList getPodList(String namespace) throws VenusException;


   /*
   * 22: 水平伸缩deployment 实例数量
   * @param namespace 应用所属空间名称
   * @param appNameKube 应用名称
   * @param replicas 期望实例数量
   * */
   public int horizontalScalingDeployment(String namespace,String appNameKube,int replicas) throws VenusException;

   /*
   * 23: 水平伸缩 StatefulSet 实例数量
   * @param namespace 应用所属空间名称
   * @param appNameKube 应用名称
   * @param replicas 期望实例数量
   * */
   public int horizontalScalingStatefulSet(String namespace,String appNameKube,int replicas) throws VenusException;

    /*
    * 24: 灰度升级,deployment
    * */
    public boolean updateDeployment(String namespace,String appNameKube,String targetImage) throws VenusException;

    /*
    * 25: 灰度升级,statefulset
    * */
    public boolean updateStatefunSet(String namespace,String appNameKube,String targetImage) throws VenusException;

    /*
    * 26: 灰度升级,DaemonSet
    * */
    public boolean updateDaemonSet(String namespace,String appNameKube,String targetImage) throws VenusException;

    /*
    * 27: 获取自动伸缩对象
    * @param namespace 应用所属空间名称
    * @param appNameKube 应用名称
    * */
    public HorizontalPodAutoscaler getHorizontalPodAutoscaler(String namespace,String hpaName) throws VenusException;

    /*
    * 29: 为当前应用,新增自动伸缩功能
    * @param namespace 应用所属空间名称
    * @param appNameKube 应用名称
    * @param minReplicas 最小实例数
    * @param maxReplicas 最大实例数
    * @param targetCpuPercent 目标cpu百分比
    * */
    public boolean addHorizontalPodAutoscaler(String namespace,String appNameKube,String hpaName,int minReplicas,int maxReplicas,int targetCpuPercent) throws VenusException;

    /*
    * 30: 修改应用的自动伸缩参数
    * @param namespace 应用所属空间名称
    * @param appNameKube 应用名称
    * @param minReplicas 最小实例数
    * @param maxReplicas 最大实例数
    * @param targetCpuPercent 目标cpu百分比
    * */
    public boolean editHorizontalPodAutoscaler(String namespace,String hpaName,int minReplicas,int maxReplicas,int targetCpuPercent) throws VenusException;

    /*
    * 31: 删除应用的自动伸缩功能
    * @param namespace 应用所属空间名称
    * @param appNameKube 应用名称
    * */
    public boolean deleteHorizontalPodAutoscaler(String namespace,String hpaName) throws VenusException;

    /*
    * 32: 删除deployment
    * */
    public boolean deleteDeployment(String namespace,String appNameKube) throws VenusException;

    /*
    * 33: 删除statefulSet
    * */
    public boolean deleteStatefulSet(String namespace,String appNameKube) throws VenusException;

    /*
    * 34: 删除daemonset
    * */
    public boolean deleteDaemonSet(String namespace,String appNameKube) throws VenusException;

    /*
    * 35: 删除pod
    * */
    public boolean deletePod(String namespace,String appNameKube) throws VenusException;

    /*
    * 36: 获取pod 事件
    * */
    public List<Event> getPodEvents(String namespace) throws VenusException;

    /*
    * 37: 根据标签,获取pod 列表
    * */
    public PodList getPodListWithLabels(String namespace,String key,String value) throws VenusException;

    ////////////////////////////////////根据选择镜像,部署应用接口///////////////////////////////////////////////////////
    /*
    * 38: 得到deployment 滚动升级的规则
    * */
    public DeploymentStrategy getDeploymentStrategy() throws VenusException;

    /*
    * 39: 得到秘钥对象
    * */
    public LocalObjectReference getLocalObjectReference(String refName) throws VenusException;

    /*
    * 40: 创建deployment 对象
    * */
    public Deployment createDployment(Deployment deployment,String namespace) throws VenusException;

    /*
    * 50: 创建service 对象
    * */
    public Service createService(Service service,String namespace) throws VenusException;

    /*
    * 创建或更新service
    * */
    public Service createOrUpdateService(String namespace,Service service) throws VenusException;

    /*
    * 51: 删除service
    * */
    public boolean deleteService(String serviceName,String namespace) throws VenusException;

    /*
    * 52: 创建statefulSet
    * */
    public StatefulSet createStatefulSet(StatefulSet statefulSet,String namespace) throws VenusException;

    /*
    * 53: 得到service对象
    * */
    public Service getService(String namespace,String serviceName) throws VenusException;

    /*
    * 54: 创建ingress
    * */
    public Ingress createIngress(String ingressName,String namespace,String appNamekube,String domainName,String serviceName,int port) throws VenusException;

   /*
   * 55: 得到service对象根据标签
   * */
   public ServiceList getServiceListByLabels(Map<String,String> map,String namespace) throws VenusException;

   /*
   * 56: 删除service,根据标签
   * */
   public boolean deleteServiceByLabels(Map<String,String> map,String namespace) throws VenusException;

   /*
   * 57: 删除ingress 根据标签
   * */
   public boolean deleteIngressByLabels(Map<String,String> map,String namespace) throws VenusException;

   /*
   * 58: 删除高可用
   * */
   public boolean deleteHPAByLabels(Map<String,String> map,String namespace) throws VenusException;


    /*
    * 59: 创建或更新deployment
    * */
    public Deployment createOrReplaceDeployment(Deployment deployment,String namespace) throws VenusException;

    /*
    * 60: 删除ingress
    * */
    public boolean deleteIngressByName(String ingressName,String namespace) throws VenusException;


    /*
    * 61: 得到ingress
    * */
    public Ingress getIngress(String namespace,String ingressName) throws VenusException;

    /**
     * 得到ingress集合列表
     * @param namespace
     * @return
     * @throws VenusException
     */
    public IngressList getIngressList(String namespace) throws VenusException;

    /*
    * 62:创建或更新ingress
    * */
    public Ingress createOrUpdateIngress(String namespace,Ingress newIngress) throws VenusException;

    /*
    * 63: 得到服务list
    * */
    public ServiceList getServiceList() throws VenusException;

    /*
    * 64: 根据命名空间得到服务list
    * */
    public ServiceList getServiceListByNamespace(String namespace) throws VenusException;



}
